<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>27、字符串形式的ref(过时的api，不推荐使用)</title>
</head>
<body>
  <div id="test"></div>

  <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  <script src="https://cdn.staticfile.org/prop-types/15.6.1/prop-types.js"></script>

  <script type="text/babel">
    class Demo extends React.Component {
      render() {
        return(
          <div>
            <input ref="input1" type="text" placeholder="点击按钮提示数据" />
            <button onClick={this.showData}>点我提示左侧的数据</button>
            <input ref="input2" onClick={this.showData2} type="text" placeholder="失去焦点提示数据" />
          </div>
        )
      }

      showData = () => {
        // this只想demo组件的实例对象
        alert(this.refs.input1.value)
      }

      showData2 = () => {
        const {input2} = this.refs
        alert(input2.value)
      }
    }
    ReactDOM.render(<Demo/>, document.getElementById('test'))
  </script>
</body>
</html>